# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import List
from fastapi import APIRouter, Request, Depends
from hypertext import R, response_json
from apps.api.schemas.agent.chat import session_schema as schema
from apps.api.service.agent.chat.session_service import ChatSessionService

router = APIRouter(prefix="/session", tags=["会话接口"])


@router.get("/lists", summary="会话列表", response_model=R[List[schema.ChatSessionListVo]])
@response_json
async def lists(request: Request, params: schema.ChatSessionSearchIn = Depends()):
    user_id = int(request.state.user_id)
    return await ChatSessionService.lists(params, user_id)


@router.post("/add", summary="会话创建", response_model=R)
@response_json
async def add(request: Request, params: schema.ChatSessionAddIn):
    user_id = int(request.state.user_id)
    return await ChatSessionService.add(params.bot, params.name, user_id)


@router.post("/edit", summary="会话编辑", response_model=R)
@response_json
async def edit(request: Request, params: schema.ChatSessionEditIn):
    user_id = int(request.state.user_id)
    return await ChatSessionService.edit(params.id, params.name, user_id)


@router.post("/delete", summary="会话删除", response_model=R)
@response_json
async def delete(request: Request, params: schema.ChatSessionDeleteIn):
    user_id = int(request.state.user_id)
    return await ChatSessionService.delete(params.id, user_id)


@router.post("/clear", summary="会话清空", response_model=R)
@response_json
async def clear(request: Request, params: schema.ChatSessionClearIn):
    user_id = int(request.state.user_id)
    return await ChatSessionService.clear(params.bot, user_id)
